package com.ml.mall.api.country;

import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.country.CountryStatesAddDto;
import com.ml.mall.bean.req.country.CountryStatesPageDto;
import com.ml.mall.bean.req.country.GetIdDto;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.entity.country.CountryStates;
import com.ml.mall.service.country.CountryStatesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "【auth】州名相关接口")
@RestController
@Slf4j
@RequestMapping("/common/states")
public class CountryStatesController {
    @Autowired
    private CountryStatesService countryStatesService;

    @ApiOperation(value = "州名添加")
    @PostMapping("/new")
//  @RequiresPermissions(PermissionConst.COMMON_STATES_NEW)//未发现调用
    public ApiRestResult addCountryStates(@RequestBody @Valid CountryStatesAddDto dto){
        int i = countryStatesService.addCountryStates(dto);
        if (i==0){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok();
    }

    @ApiOperation(value = "分页查询州名和国家id")
    @PostMapping("/query_page")
//  @RequiresPermissions(PermissionConst.COMMON_STATES_QUERY_PAGE)
    public com.ml.mall.bean.page.Page<CountryStates> queryAllCountryStatesByPage(@RequestBody @Valid CountryStatesPageDto dto){
        com.ml.mall.bean.page.Page<CountryStates> countryStatesPageRes = countryStatesService.queryAllCountryStatesByPage(dto);
        return countryStatesPageRes;
    }

    @ApiOperation(value = "州名的批量删除")
    @PostMapping("/del")
//  @RequiresPermissions(PermissionConst.COMMON_STATES_DEL)//未发现调用
    public ApiRestResult delCountryStates(@RequestBody GetIdDto dto){
        int i = countryStatesService.deleteStatesByBatchId(dto);
        if (i==0){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok();
    }
}
